/*
 ============================================================================
 Name		: SoundPlayer.cpp
 Author	  : 
 Version	 : 1.0
 Copyright   : Your copyright notice
 Description : CSoundPlayer implementation
 ============================================================================
 */

#include "SoundPlayer.h"

CSoundPlayer::CSoundPlayer()
	{
	// No implementation required
	}

CSoundPlayer::~CSoundPlayer()
	{
	}

CSoundPlayer* CSoundPlayer::NewLC(const TDesC& aFile)
	{
	CSoundPlayer* self = new (ELeave) CSoundPlayer();
	CleanupStack::PushL(self);
	self->ConstructL(aFile);
	return self;
	}

CSoundPlayer* CSoundPlayer::NewL(const TDesC& aFile)
	{
	CSoundPlayer* self = CSoundPlayer::NewLC(aFile);
	CleanupStack::Pop(); // self;
	return self;
	}

void CSoundPlayer::ConstructL(const TDesC& aFile)
	{
	 //
	 // Create a file audio player utility instance
	 //
	 iMdaPlayer=CMdaAudioPlayerUtility::NewFilePlayerL(aFile,*this);

	}
//
// Implementation 1: set a iState flag to ready
// to reflect the fact that the player is ready
//
//void CSoundPlayer::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
//{
//   iState = aError ? ENotReady : EReady;
//}


//
// Implementation 2: play the file immediately
//
void CSoundPlayer::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
{
   if (!aError)
       iMdaPlayer->Play();
}

void CSoundPlayer::PlayL()
{
   if(iState==EReady)
   {
       iState=EPlaying;
       iMdaPlayer->Play();
   }
}

void CSoundPlayer::MapcPlayComplete(TInt aError)
{
   iState = aError ? ENotReady : EReady;
}
